package co.fitstart.mobile.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.demo2do.core.persistence.GenericDaoSupport;

import co.fitstart.entity.course.round.CourseRound;
import co.fitstart.entity.course.round.Goal;
import co.fitstart.entity.courseware.assessment.BasicData;
import co.fitstart.entity.courseware.assessment.PostureJoint;
import co.fitstart.entity.courseware.assessment.StudentHabit;
import co.fitstart.entity.user.basic.BodyDataTarget;
import co.fitstart.mobile.service.BasicInformationService;

/**
 * 基础信息
 * @author haiyan_xiao
 *
 */
@Service("basicInformationService")
public class BasicInformationServiceImpl implements BasicInformationService {

    @Autowired
    private GenericDaoSupport genericDaoSupport;
    
    /*
     * (non-Javadoc)
     * @see co.fitstart.mobile.service.BasicInformationService#loadGoal(co.fitstart.entity.course.round.CourseRound)
     */
    public Goal loadGoal(CourseRound courseRound) {
        return genericDaoSupport.searchForObject("FROM Goal WHERE disabled=false AND courseRound = :courseRound", "courseRound", courseRound, Goal.class);
    }
    
    /*
     * (non-Javadoc)
     * @see co.fitstart.mobile.service.BasicInformationService#loadBasicData(co.fitstart.entity.course.round.CourseRound)
     */
    public BasicData loadBasicData(CourseRound courseRound) {
        return genericDaoSupport.searchForObject("FROM BasicData WHERE disabled = false"
                + " AND courseRound = :courseRound", "courseRound", courseRound, BasicData.class);
    }
    
    /*
     * (non-Javadoc)
     * @see co.fitstart.mobile.service.BasicInformationService#loadPostureJoint(co.fitstart.entity.course.round.CourseRound)
     */
    public PostureJoint loadPostureJoint(CourseRound courseRound) {
        return genericDaoSupport.searchForObject("FROM PostureJoint WHERE disabled = false"
                + " AND courseRound = :courseRound", "courseRound", courseRound, PostureJoint.class);
    }
    
    /*
     * (non-Javadoc)
     * @see co.fitstart.coach.service.BasicInformationService#listBodyDataTarget(co.fitstart.entity.course.round.CourseRound)
     */
    @SuppressWarnings("unchecked")
    public List<BodyDataTarget> listBodyDataTarget(CourseRound courseRound) {
        return genericDaoSupport.searchForList("FROM BodyDataTarget WHERE disabled = false AND courseRound = :courseRound", "courseRound", courseRound);
    }

    /*
     * (non-Javadoc)
     * @see co.fitstart.coach.service.BasicInformationService#loadStudentHabit(co.fitstart.entity.course.round.CourseRound)
     */
    public StudentHabit loadStudentHabit(CourseRound courseRound) {
        return genericDaoSupport.searchForObject("FROM StudentHabit WHERE disabled = false AND courseRound = :courseRound", "courseRound", courseRound, StudentHabit.class);
    }
}
